import { IPhones, IState } from '../typings';
import { useSelector } from 'react-redux';

/**
 * @description 该自定义hook 完成根据用户传入id查找state里符合的某项数据
 * @returns 符合条件的某项phoneList
 */
function usePhoneDetail(id: string): IPhones | undefined {
  const phoneList = useSelector((state: IState) => state.phoneList);

  //返回请求数据后的phoneList
  return phoneList.find((phone: IPhones) => phone.id === parseInt(id));
}

export default usePhoneDetail;
